#pragma once

#include <stdint.h>

class gdbPacket
{
public:
    gdbPacket(uint32_t bufsz = 1029);
    ~gdbPacket();

    char* request();
    uint32_t bufsz();
    uint32_t length();
    void resetRecvBuf();
    bool putRecvBuf(char c);
    void resetSendBuf();
    bool check(uint32_t dlen);
    bool append(char c);
    bool append(const char *str, int len = -1);
    bool append(uint8_t d);//will cover DEC to HEX string(e.g 0 -> "00")
    bool append(uint8_t *d, uint32_t len);
    char getCmd();
    char* response(uint32_t *len = 0);
    uint32_t addPos(uint32_t len);
    uint8_t checkSum(char *d, int len);
    bool makeResponse();
    char *data(uint32_t pos = 1);

public:
    bool replyStop();
    bool replyEmpty();
    bool replyOk();
    bool replySignal(uint8_t sig);
    bool replyError(uint8_t eno = 14);

private:
    char *_buf;
    uint32_t _bufsz;
    uint32_t _dlen;
    char *_sbuf;
    uint32_t _sdlen;
    uint32_t _sbufsz;
};
